package com.eastfair.venueservice.controller;

import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.venueservice.entity.ServiceAuditRecord;
import com.eastfair.venueservice.dto.ServiceAuditRecordSaveDTO;
import com.eastfair.venueservice.dto.ServiceAuditRecordUpdateDTO;
import com.eastfair.venueservice.dto.ServiceAuditRecordPageQuery;
import com.eastfair.venueservice.service.ServiceAuditRecordService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import com.eastfair.venueservice.vo.ServiceAuditRecordVO;
import com.eastfair.venueservice.vo.ServiceSpecsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eastfair.boot.request.PageParams;
import com.eastfair.core.context.ContextUtil;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 服务审核记录
 * </p>
 *
 * @author lyw
 * @date 2022-07-13
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/serviceAuditRecord")
@Api(value = "ServiceAuditRecord", tags = "服务审核记录")
@PreAuth(replace = "venueservice:serviceAuditRecord:")
public class ServiceAuditRecordController extends SuperController<ServiceAuditRecordService, Long, ServiceAuditRecord, ServiceAuditRecordPageQuery, ServiceAuditRecordSaveDTO, ServiceAuditRecordUpdateDTO> {

    @Autowired
    private EchoService echoService;
    @Autowired
    private  ServiceAuditRecordService serviceAuditRecordService;

    @Override
    public void handlerResult(IPage<ServiceAuditRecord> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<ServiceAuditRecord> serviceAuditRecordList = list.stream().map((map) -> {
            ServiceAuditRecord serviceAuditRecord = ServiceAuditRecord.builder().build();
            //TODO 请在这里完成转换
            return serviceAuditRecord;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(serviceAuditRecordList));
    }



    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<ServiceAuditRecordPageQuery> params) {
        ServiceAuditRecordPageQuery pageQuery = params.getModel();
        //分页处理
        if(ContextUtil.getProjectId()!=null){
            pageQuery.setProjectId(ContextUtil.getProjectId());
        }
    }


    /**
     * 审核服务
     * @param id
     * @return
     */
    @ApiOperation(value = "审核服务")
    @SysLog("审核服务")
    @GetMapping(value = "/auditServiceItemById/{id}/{auditState}")
    public R<Boolean> auditServiceItemById(@PathVariable("id") Long id,@PathVariable("auditState") String auditState){
        return R.success(serviceAuditRecordService.auditServiceItemById(id,auditState));
    }




}
